import { Component } from '@angular/core';

@Component({
    selector: 'pager',
    templateUrl: 'app/component/pager/pager.component.html'
})
export class PagerComponent {
    PageIndex: number = 1;
    PageCount: number = 10;
    TotalPage: any[];
    TotalPageCount: number;

    Load(totalCount: number) {
        this.TotalPage = [];
        this.TotalPageCount = Math.ceil(totalCount / this.PageCount);
        console.log(this.TotalPageCount);
        
        for (let i = 1; i <= this.TotalPageCount; i++) {
            this.TotalPage.push(i);
        }
    }
    next_click() {
        let p = this.PageIndex + 1;
        if (p > this.TotalPageCount) return;

        this.PageIndex = p;
        this.OnPageIndexChanged(this.PageIndex);
    }
    previous_click() {
        let p = this.PageIndex - 1;
        if (p < 1) return;

        this.PageIndex = p;
        this.OnPageIndexChanged(this.PageIndex);
    }
    page_click(pageIndex: number) {
        console.log('page_click', pageIndex);
        this.PageIndex = pageIndex;
        this.OnPageIndexChanged(pageIndex);
    }

    OnPageIndexChanged: (pageIndex: number) => void;
}